package com.codinghero.zqlb.match;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.codinghero.util.DateUtils;
import com.codinghero.util.ListUtils;
import com.codinghero.util.MapUtils;
import com.codinghero.util.StringUtils;

public class SoccerMatch implements DateSortable {
	
	// focused + common = white ; unfocused = black
	
	// match type 
	public static Map<Integer, String> FOCUSED_TYPE_ID_MAP = new LinkedHashMap<Integer, String>();
	public static Map<Integer, String> COMMON_TYPE_ID_MAP = new LinkedHashMap<Integer, String>();
	public static Map<Integer, String> WHITE_TYPE_ID_MAP = new LinkedHashMap<Integer, String>();
	public static Map<String, Integer> FOCUSED_TYPE_MAP;
	public static Map<String, Integer> COMMON_TYPE_MAP;
	public static Map<String, Integer> WHITE_TYPE_MAP = new LinkedHashMap<String, Integer>();
	public static Map<String, Integer> BLACK_TYPE_MAP = new LinkedHashMap<String, Integer>();
	
	// match team
	public static Map<Integer, String> FOCUSED_TEAM_ID_MAP = new LinkedHashMap<Integer, String>();
	public static Map<Integer, String> COMMON_TEAM_ID_MAP = new LinkedHashMap<Integer, String>();
	public static Map<Integer, String> WHITE_TEAM_ID_MAP = new LinkedHashMap<Integer, String>();
	
	public static Map<String, Integer> FOCUSED_TEAM_MAP;
	public static Map<String, Integer> COMMON_TEAM_MAP;
	public static Map<String, Integer> WHITE_TEAM_MAP = new LinkedHashMap<String, Integer>();

	public static Map<String, Integer> CHANNEL_MAP;
	public static Map<Integer, String> CHANNEL_ID_MAP = new LinkedHashMap<Integer, String>();
	// public static Map<Integer, Integer> CHANNEL_URL_MAP = new HashMap<Integer, String>();
	
	//public static Map<Integer, LiveChannel> LIVE_CHANNEL_MAP = new LinkedHashMap<Integer, LiveChannel>();
	//public static Map<Integer, String> LIVE_SITE_MAP = new LinkedHashMap<Integer, String>();
	public static Map<String, String> FYZB_CHN_URL_MAP = new LinkedHashMap<String, String>();
	public static Map<String, Integer> JUNK_MAP = new LinkedHashMap<String, Integer>();
	
	static {
		
		/**
		 * 1-99世界大赛，
		 * 100-199亚洲洲际比赛，200-299欧洲洲际比赛，300-399南美洲洲际比赛，……
		 * 10000-19999亚洲联赛&杯赛，20000-29999欧洲联赛&杯赛，……
		 */
		FOCUSED_TYPE_ID_MAP.put(1, "世界杯");
		FOCUSED_TYPE_ID_MAP.put(2, "世俱");
		FOCUSED_TYPE_ID_MAP.put(3, "丰田");
		FOCUSED_TYPE_ID_MAP.put(100, "亚洲杯");
		FOCUSED_TYPE_ID_MAP.put(101, "亚冠");
		FOCUSED_TYPE_ID_MAP.put(10000, "中超");
		FOCUSED_TYPE_ID_MAP.put(10001, "足协杯");
		FOCUSED_TYPE_ID_MAP.put(200, "欧洲杯");
		FOCUSED_TYPE_ID_MAP.put(201, "欧冠");
		FOCUSED_TYPE_ID_MAP.put(202, "欧联");
		FOCUSED_TYPE_ID_MAP.put(20000, "英超");
		FOCUSED_TYPE_ID_MAP.put(20001, "足总杯");
		FOCUSED_TYPE_ID_MAP.put(20010, "西甲");
		FOCUSED_TYPE_ID_MAP.put(20011, "国王杯");
		FOCUSED_TYPE_ID_MAP.put(20020, "德甲");
		FOCUSED_TYPE_ID_MAP.put(20030, "意甲");
		FOCUSED_TYPE_ID_MAP.put(20031, "意大利杯");
		FOCUSED_TYPE_ID_MAP.put(20032, "意大利超级杯");
		// basketball match
		FOCUSED_TYPE_ID_MAP.put(100003, "NBA");
		FOCUSED_TYPE_ID_MAP.put(100004, "CBA");
		FOCUSED_TYPE_MAP = MapUtils.reverse(FOCUSED_TYPE_ID_MAP);
		FOCUSED_TYPE_MAP.put("亚洲冠军联赛", 101);
		FOCUSED_TYPE_MAP.put("欧洲冠军联赛", 201);

		// other football match
		COMMON_TYPE_ID_MAP.put(300, "南美洲杯");
		COMMON_TYPE_ID_MAP.put(301, "解放者");
		COMMON_TYPE_ID_MAP.put(10, "女足");
		COMMON_TYPE_ID_MAP.put(11, "阿尔加夫");
		COMMON_TYPE_ID_MAP.put(12, "土伦");
		// basketball match
		COMMON_TYPE_ID_MAP.put(100001, "男篮");
		COMMON_TYPE_ID_MAP.put(100000, "篮球");
		COMMON_TYPE_ID_MAP.put(100002, "女篮");
		COMMON_TYPE_MAP = MapUtils.reverse(COMMON_TYPE_ID_MAP);
		
		WHITE_TYPE_ID_MAP.putAll(FOCUSED_TYPE_ID_MAP);
		WHITE_TYPE_ID_MAP.putAll(COMMON_TYPE_ID_MAP);
		WHITE_TYPE_MAP.putAll(FOCUSED_TYPE_MAP);
		WHITE_TYPE_MAP.putAll(COMMON_TYPE_MAP);
		
		/**
		 * 异常情况100000-999999
		 */
		BLACK_TYPE_MAP.put("排球", 100010);
		BLACK_TYPE_MAP.put("男排", 100011);
		BLACK_TYPE_MAP.put("女排", 100012);
		BLACK_TYPE_MAP.put("台球", 100020);
		BLACK_TYPE_MAP.put("斯诺克", 100021);
		BLACK_TYPE_MAP.put("汽车", 100030);
		BLACK_TYPE_MAP.put("赛车", 100031);
		BLACK_TYPE_MAP.put("F1", 100032);
		BLACK_TYPE_MAP.put("拉力", 100033);
		BLACK_TYPE_MAP.put("摩托车", 100034);
		BLACK_TYPE_MAP.put("橄榄球", 100040);
		BLACK_TYPE_MAP.put("MLB", 100041);
		BLACK_TYPE_MAP.put("棒球", 100050);
		BLACK_TYPE_MAP.put("网球", 100060);
		BLACK_TYPE_MAP.put("澳网", 100061);
		BLACK_TYPE_MAP.put("温网", 100062);
		BLACK_TYPE_MAP.put("美网", 100063);
		BLACK_TYPE_MAP.put("法网", 100064);
		BLACK_TYPE_MAP.put("高尔夫", 100070);
		BLACK_TYPE_MAP.put("田径", 100080);
		BLACK_TYPE_MAP.put("田联", 100081);
		BLACK_TYPE_MAP.put("马拉松", 100081);
		BLACK_TYPE_MAP.put("NBL", 100090);
		BLACK_TYPE_MAP.put("NHL", 100091);
		BLACK_TYPE_MAP.put("羽毛球", 100100);
		BLACK_TYPE_MAP.put("羽超", 100101);
		BLACK_TYPE_MAP.put("羽联", 100102);
		BLACK_TYPE_MAP.put("拳击", 100110);
		BLACK_TYPE_MAP.put("拳王", 100111);
		BLACK_TYPE_MAP.put("龙舟", 100120);
		// match type end
		

		/**
		 * 100-199亚洲，200-299欧洲，300-399南美洲，400-499北美洲，500-599非洲，600-699大洋洲
		 * 10000-19999亚洲俱乐部，20000-29999欧洲俱乐部，30000-39999南美洲俱乐部
		 */
		FOCUSED_TEAM_ID_MAP.put(100, "中国");
		FOCUSED_TEAM_ID_MAP.put(200, "西班牙");
		FOCUSED_TEAM_ID_MAP.put(201, "意大利");
		FOCUSED_TEAM_ID_MAP.put(202, "法国");
		FOCUSED_TEAM_ID_MAP.put(203, "英格兰");
		FOCUSED_TEAM_ID_MAP.put(204, "葡萄牙");
		FOCUSED_TEAM_ID_MAP.put(205, "德国");
		FOCUSED_TEAM_ID_MAP.put(206, "荷兰");
		FOCUSED_TEAM_ID_MAP.put(300, "巴西");
		FOCUSED_TEAM_ID_MAP.put(301, "阿根廷");
		
		FOCUSED_TEAM_ID_MAP.put(10000, "国安");
		FOCUSED_TEAM_ID_MAP.put(10001, "恒大");
		FOCUSED_TEAM_ID_MAP.put(10002, "鲁能");
		FOCUSED_TEAM_ID_MAP.put(10004, "申花");
		FOCUSED_TEAM_ID_MAP.put(10005, "舜天");
		FOCUSED_TEAM_ID_MAP.put(10008, "贵州茅台");
		FOCUSED_TEAM_ID_MAP.put(10010, "富力");
		FOCUSED_TEAM_ID_MAP.put(10012, "阿尔滨");
		
		FOCUSED_TEAM_ID_MAP.put(20000, "皇家马德里");
		FOCUSED_TEAM_ID_MAP.put(20001, "巴塞罗那");
		FOCUSED_TEAM_ID_MAP.put(20100, "尤文图斯");
		FOCUSED_TEAM_ID_MAP.put(20101, "AC米兰");
		FOCUSED_TEAM_ID_MAP.put(20102, "国际米兰");
		FOCUSED_TEAM_ID_MAP.put(20300, "曼联");
		FOCUSED_TEAM_ID_MAP.put(20301, "阿森纳");
		FOCUSED_TEAM_ID_MAP.put(20302, "切尔西");
		FOCUSED_TEAM_ID_MAP.put(20303, "曼城");
		FOCUSED_TEAM_ID_MAP.put(20304, "热刺");
		FOCUSED_TEAM_ID_MAP.put(20305, "利物浦");
		FOCUSED_TEAM_ID_MAP.put(20500, "拜仁慕尼黑");
		FOCUSED_TEAM_ID_MAP.put(20501, "多特蒙德");
		FOCUSED_TEAM_MAP = MapUtils.reverse(FOCUSED_TEAM_ID_MAP);
		FOCUSED_TEAM_MAP.put("贵州人和", 10008);

		COMMON_TEAM_ID_MAP.put(10003, "实德");
		COMMON_TEAM_ID_MAP.put(10006, "亚泰");
		COMMON_TEAM_ID_MAP.put(10007, "建业");
		COMMON_TEAM_ID_MAP.put(10009, "中能");
		COMMON_TEAM_ID_MAP.put(10011, "绿城");
		COMMON_TEAM_ID_MAP.put(10013, "宏运");
		COMMON_TEAM_ID_MAP.put(10014, "申鑫");
		COMMON_TEAM_ID_MAP.put(10015, "泰达");
		
		COMMON_TEAM_ID_MAP.put(101, "韩国");
		COMMON_TEAM_ID_MAP.put(102, "日本");
		COMMON_TEAM_ID_MAP.put(103, "朝鲜");
		COMMON_TEAM_ID_MAP.put(104, "蒙古");
		COMMON_TEAM_ID_MAP.put(110, "沙特");
		COMMON_TEAM_ID_MAP.put(111, "伊朗");
		COMMON_TEAM_ID_MAP.put(112, "伊拉克");
		COMMON_TEAM_ID_MAP.put(113, "阿联酋");
		COMMON_TEAM_ID_MAP.put(114, "科威特");
		COMMON_TEAM_ID_MAP.put(115, "巴林");
		COMMON_TEAM_ID_MAP.put(116, "阿曼");
		COMMON_TEAM_ID_MAP.put(140, "泰国");
		COMMON_TEAM_ID_MAP.put(141, "越南");
		COMMON_TEAM_ID_MAP.put(142, "老挝");
		COMMON_TEAM_ID_MAP.put(170, "乌兹别克斯坦");
		COMMON_TEAM_ID_MAP.put(180, "澳大利亚");
		COMMON_TEAM_ID_MAP.put(181, "新西兰");
		
		COMMON_TEAM_ID_MAP.put(216, "白俄罗斯");
		COMMON_TEAM_ID_MAP.put(217, "北爱尔兰");
		COMMON_TEAM_ID_MAP.put(207, "波兰");
		COMMON_TEAM_ID_MAP.put(208, "希腊");
		COMMON_TEAM_ID_MAP.put(209, "俄罗斯");
		COMMON_TEAM_ID_MAP.put(210, "捷克");
		COMMON_TEAM_ID_MAP.put(211, "丹麦");
		COMMON_TEAM_ID_MAP.put(212, "爱尔兰");
		COMMON_TEAM_ID_MAP.put(213, "克罗地亚");
		COMMON_TEAM_ID_MAP.put(214, "乌克兰");
		COMMON_TEAM_ID_MAP.put(215, "瑞典");
		COMMON_TEAM_MAP = MapUtils.reverse(COMMON_TEAM_ID_MAP);

		WHITE_TEAM_ID_MAP.putAll(FOCUSED_TEAM_ID_MAP);
		WHITE_TEAM_ID_MAP.putAll(COMMON_TEAM_ID_MAP);
		WHITE_TEAM_MAP.putAll(FOCUSED_TEAM_MAP);
		WHITE_TEAM_MAP.putAll(COMMON_TEAM_MAP);
		// team end
		
		// channel start
		CHANNEL_ID_MAP.put(1, "CCTV5");
		CHANNEL_ID_MAP.put(2, "风云足球");
		CHANNEL_ID_MAP.put(3, "CCTV1");
		CHANNEL_ID_MAP.put(4, "CCTV2");
		CHANNEL_ID_MAP.put(10, "北京体育");
		CHANNEL_ID_MAP.put(11, "广东体育");
		CHANNEL_ID_MAP.put(12, "上海体育");
		CHANNEL_ID_MAP.put(13, "纬来体育");
		CHANNEL_ID_MAP.put(14, "澳视体育");
		CHANNEL_ID_MAP.put(15, "卫视体育台湾");
		CHANNEL_ID_MAP.put(21, "新浪中超1台");
		CHANNEL_ID_MAP.put(22, "新浪中超2台");
		CHANNEL_ID_MAP.put(23, "新浪中超3台");
		CHANNEL_ID_MAP.put(24, "新浪中超4台");
		CHANNEL_ID_MAP.put(25, "新浪中超5台");
		CHANNEL_ID_MAP.put(26, "新浪中超6台");
		CHANNEL_ID_MAP.put(27, "新浪中超7台");
		CHANNEL_ID_MAP.put(30, "PPTV");
		CHANNEL_ID_MAP.put(40, "风云NBA-10");
		CHANNEL_ID_MAP.put(31, "风云NBA-1");
		CHANNEL_ID_MAP.put(32, "风云NBA-2");
		CHANNEL_ID_MAP.put(33, "风云NBA-3");
		CHANNEL_ID_MAP.put(34, "风云NBA-4");
		CHANNEL_ID_MAP.put(35, "风云NBA-5");
		CHANNEL_ID_MAP.put(36, "风云NBA-6");
		CHANNEL_ID_MAP.put(37, "风云NBA-7");
		CHANNEL_ID_MAP.put(38, "风云NBA-8");
		CHANNEL_ID_MAP.put(39, "风云NBA-9");
		CHANNEL_ID_MAP.put(41, "体育直播信号-1");
		CHANNEL_ID_MAP.put(42, "体育直播信号-2");
		CHANNEL_ID_MAP.put(43, "体育直播信号-3");
		CHANNEL_ID_MAP.put(44, "体育直播信号-4");
		CHANNEL_ID_MAP.put(45, "体育直播信号-5");
		CHANNEL_ID_MAP.put(45, "体育直播信号-5");
		CHANNEL_ID_MAP.put(45, "体育直播信号-5");
		CHANNEL_ID_MAP.put(51, "爱尔达体育");
		CHANNEL_MAP = MapUtils.reverse(CHANNEL_ID_MAP);
		CHANNEL_MAP.put("cctv5", 1);
		CHANNEL_MAP.put("BTV6", 10);
		CHANNEL_MAP.put("五星体育", 12);
		CHANNEL_MAP.put("上海五星体育", 12);
		CHANNEL_MAP.put("PPlive", 30);
		CHANNEL_MAP.put("PPLive", 30);
		// channel end
		
		// JUNK_MAP.put("插件", 1);
		JUNK_MAP.put("比分直播", 2);
		JUNK_MAP.put("直播吧", 3);
		JUNK_MAP.put("足球经理", 4);
		JUNK_MAP.put("彩票", 5);
		JUNK_MAP.put("新用户送彩票", 6);
		JUNK_MAP.put("美女视频直播", 7);
		JUNK_MAP.put("直播吧安卓版", 8);
		JUNK_MAP.put("购买篮球彩票", 8);
	}

	/**
	 * 1世界杯，2欧洲杯，3亚洲杯，4南美洲杯，6北美洲杯，7非洲杯<br/>
	 * 11世俱，12欧冠，13亚冠，14欧联，15欧洲超级杯，16南美解放者 31英超，32西甲，33意甲，34德甲，35法甲， 101中超
	 */
	private Integer id;
	private Integer typeId;
	private String typeName;

	private Date startDate;
	private Date endDate;
	private String startDateStr;

	private Integer team1Id;
	private Integer team2Id;
	private String team1Name;
	private String team2Name;
	
	private Integer typeFocused = 0;
	private Integer team1Focused = 0;
	private Integer team2Focused = 0;
	
	private String channelNames;
	private List<String> channelNameList = new ArrayList<String>();
	private String channelIds;
	private Set<Integer> channelIdSet = new HashSet<Integer>();
	
	private String channelStr = "";
	
	/**
	 * 0未审核，1审核通过，2审核失败
	 */
	private Integer status = 0;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
		if (startDate != null) {
			setStartDateStr(DateUtils.getTimeStr(startDate));
		}
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getStartDateStr() {
		return startDateStr;
	}

	public void setStartDateStr(String startDateStr) {
		this.startDateStr = startDateStr;
	}

	public String getTeam1Name() {
		return team1Name;
	}

	public void setTeam1Name(String team1Name) {
		this.team1Name = team1Name;
	}

	public String getTeam2Name() {
		return team2Name;
	}

	public void setTeam2Name(String team2Name) {
		this.team2Name = team2Name;
	}

	public Integer getTeam1Id() {
		return team1Id;
	}

	public void setTeam1Id(Integer team1Id) {
		this.team1Id = team1Id;
	}

	public Integer getTeam2Id() {
		return team2Id;
	}

	public void setTeam2Id(Integer team2Id) {
		this.team2Id = team2Id;
	}

	public Integer getTypeId() {
		return typeId;
	}

	public void setTypeId(Integer typeId) {
		this.typeId = typeId;
	}

	public String getTypeName() {
		return typeName;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public Integer getTypeFocused() {
		return typeFocused;
	}

	public void setTypeFocused(Integer typeFocused) {
		this.typeFocused = typeFocused;
	}

	public Integer getTeam1Focused() {
		return team1Focused;
	}

	public void setTeam1Focused(Integer team1Focused) {
		this.team1Focused = team1Focused;
	}

	public Integer getTeam2Focused() {
		return team2Focused;
	}

	public void setTeam2Focused(Integer team2Focused) {
		this.team2Focused = team2Focused;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getChannelNames() {
		return channelNames;
	}

	public void setChannelNames(String channelNames) {
		this.channelNames = channelNames;
	}

	public void setChannelNames(List<String> channelNameList) {
		this.channelNames = StringUtils.join(channelNameList, ",");
	}

	public List<String> getChannelNameList() {
		return channelNameList;
	}

	public void setChannelNameList(List<String> channelNameList) {
		this.channelNameList = channelNameList;
	}

	public String getChannelIds() {
		return channelIds;
	}

	public void setChannelIds(String channelIds) {
		this.channelIds = channelIds;
		if (!StringUtils.isEmpty(channelIds)) {
			List<String> list = StringUtils.split(channelIds, ",");
			for(String id:list) {
				channelIdSet.add(Integer.parseInt(id));
			}
		}
	}

	public void setChannelIds(Set<Integer> channelIdSet) {
		this.channelIds = StringUtils.join(channelIdSet, ",");
	}
	
	public void refreshChannelIds() {
		this.channelIds = StringUtils.join(channelIdSet, ",");
	}

	public Set<Integer> getChannelIdSet() {
		return channelIdSet;
	}

	public void setChannelIdSet(Set<Integer> channelIdSet) {
		this.channelIdSet = channelIdSet;
	}

	public String getChannelStr() {
		return channelStr;
	}

	public void setChannelStr(String channelStr) {
		this.channelStr = channelStr;
	}

	public String getShortInfo() {
		
		String teamVs = "";
		if (!StringUtils.isEmpty(getTeam1Name())) {
			teamVs = getTeam1Name();
			if (!StringUtils.isEmpty(getTeam2Name())) {
				teamVs += (" - " + getTeam2Name());
			}
		}
		
		StringBuilder sb = new StringBuilder();
		sb.append(DateUtils.format(startDate, "HH:mm"));
		sb.append(" ");
		sb.append(typeName);
		sb.append(" ");
		sb.append(teamVs);
		
		return sb.toString();
	}

	public static String getShortInfo(List<SoccerMatch> matches) {
		if (ListUtils.isEmpty(matches))
			return null;
		StringBuilder sb = new StringBuilder();
		for (int i=0; i<matches.size(); i++) {
			SoccerMatch match = matches.get(i);
			if (i != 0)
				sb.append("，");
			sb.append(match.getShortInfo());
		}
		return sb.toString();
			
	}

	@Override
	public Date fetchSortedDate() {
		return this.startDate;
	}
}
